home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 9164 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: anvil.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.c++,comp.lang.c
  4. Subject: Re: Embedding Binary Data File in .EXE
  5. Date: 27 Feb 1996 08:38:49 -0800
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Message-ID: <4gvc2pINNdf7@anvil.ugrad.cs.ubc.ca>
  8. References: <312b88d2.13833883@news.uwaterloo.ca>
  9. NNTP-Posting-Host: anvil.ugrad.cs.ubc.ca
  10.  
  11. In article <312b88d2.13833883@news.uwaterloo.ca>,
  12. Mark Nebelung <mrnebelu@undergrad.math.uwaterloo.ca> wrote:
  13. >Hi there,
  14. >
  15. >I was just wondering on the best way to embed a binary file in an
  16. >executible.
  17. >
  18. >I have an FLI file that I would like to make self-executible.  I have
  19. >all the display routines, but now I just want to know how I can tag on
  20. >the FLI file to my display executible.
  21. >
  22. >I using Borland C++, and the code is to run under DOS.
  23.  
  24. One obvious way is to declare a big array of type char, and store the FLI in
  25. there. A simple utility program can be written that will turn binary files
  26. into C array declarations.
  27.  
  28. You then compile and link the result. The intermediate C code for the
  29. declaration will likely be somewhat of a bloat, of course, on the order of at
  30. least 5x bigger than the original datafile.
  31.  
  32. Have your program spit out something like:
  33.  
  34. char data[] = {
  35.     0xff,0x39,0x55,0xeD,...
  36. };
  37.  
  38. The sizeof(data) will give you the number of bytes in the array.
  39.  
  40. Of course, the platform you are working on probably won't let you have arrays
  41. bigger than 64K unless you mess with some weird memory model business.
  42.  
  43. Ad-hoc techniques like appending data to executable files not something I'd
  44. recommend, though.
  45.  
  46. This is the closest thing to a C answer that I can come up with.
  47.  
  48. -- 
  49.  
  50.